package com.ywger.web.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ywger.service.dto.request.EnsRegisterParam;
import com.ywger.service.dto.response.EnsStateRes;
import com.ywger.service.result.Result;
import com.ywger.service.server.EnsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author chenmeng
 * @date 2021-11-13 20:55
 * @desc
 */
@Api(tags = "ENS")
@RestController
@RequestMapping("/ens")
public class EnsController {

    @Autowired
    private EnsService ensService;



    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "检查ENS是否可用、已注册")
    @PostMapping("/check")
    public  Result<EnsStateRes> checkEnsName(@RequestBody  List<String> ensNameList){
        return Result.ofSuccess(ensService.checkEnsName(ensNameList));
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "批量注册ENS")
    @PostMapping("/register")
    public  Result register(@RequestBody @Valid EnsRegisterParam param){
        EnsStateRes ensStateResResult = ensService.register(param);
        return Result.ofSuccess(ensStateResResult);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "查询ENS注册状态")
    @PostMapping("/groupEnsState")
    public  Result groupEnsState(){
        return Result.ofSuccess(ensService.getEnsState());
    }


    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "ENS 未上链状态ENS重新注册")
    @PostMapping("/retry/pending")
    public  Result retry(@RequestBody  List<String> ensNameList){
        ensService.retry(ensNameList);
        return Result.ofSuccess();
    }

    @ApiOperation(value = "实时同步链上交易状态")
    @ApiOperationSupport(order = 5)
    @GetMapping("/dealPending")
    public  Result dealPending(){
        ensService.dealPending();
        return Result.ofSuccess();
    }





}
